var cp = require('child_process');

var createWorker = function (){
    var server = startServer();
    process.on('SIGTERM', function(){
        console.log('master '+ process.pid + ' exited!');
        server.kill();
    });
}

function startServer(){
    var server = cp.fork(__dirname + '/main.js');
    server.on('exit', function(){
        console.log('server '+ server.pid + ' exited!');
        delete (server);
    });
    /*server.on('message', function(message){
       if(message.act === 'suicide'){
           startServer();
       }
    });*/
    return server;
}

createWorker();